package com.nhc.database.dbmodel;

import com.astrob.NavFrameSDK;
import com.astrob.model.GeoHash;
import com.astrob.model.LonLat;
import com.astrob.nhcmap.R;
import com.astrob.util.Utils;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.Transient;

/**
 * http://www.cnblogs.com/dsxniubility/archive/2016/07/28/5699543.html
 * Created by wsf on 2017/5/16.
 */
@Entity
public class WayPoint {

    @Id(autoincrement = true)
    private Long id;
    private int icon_num = 0; //图标
    private String name = ""; //名称
    //因为要更改小数点后8位，所以只能保存原始经纬度，只有在显示的时候才转换。
    private double longitude = 0;//经度
    private double latitude = 0;//纬度
    private double altitude = 0;//海拔高度
    private String note = "";

    private double depth = 0; //深度
    private long datetime = 0; //时间
    private String picurl = ""; //图片地址
    private int type = 0;//航点类型 0-正常点 1-警告点
    private double range = 0;//警告点范围 米--- （需得是double-否则单位变化会有误差）
    private int localtype = 0;//0-wgs84 1-GCJ-02   ---默认保存都是wgs84

    private Long routeid = 0l;//航线id 航点列表只显示不在航线里的航点

    @Index
    private String geohash = "";

    @Transient
    public static final int[] TYPE_IDS = {
            R.drawable.tourism_type01, R.drawable.tourism_type02, R.drawable.tourism_type03,
            R.drawable.tourism_type04, R.drawable.tourism_type05, R.drawable.tourism_type06,
            R.drawable.tourism_type07, R.drawable.tourism_type08, R.drawable.tourism_type09,
            R.drawable.tourism_type10, R.drawable.tourism_type11, R.drawable.tourism_type12};

    @Transient
    public static final int[] TYPE_IDS_L = {
            R.drawable.tourism_type01_l, R.drawable.tourism_type02_l, R.drawable.tourism_type03_l,
            R.drawable.tourism_type04_l, R.drawable.tourism_type05_l, R.drawable.tourism_type06_l,
            R.drawable.tourism_type07_l, R.drawable.tourism_type08_l, R.drawable.tourism_type09_l,
            R.drawable.tourism_type10_l, R.drawable.tourism_type11_l, R.drawable.tourism_type12_l};

    @Transient
    private double distance = 0;//排序使用

    @Transient
    public String strDate = "";//日期标签

    public String strLL = "";//如果编辑的是大地坐标则使用这个坐标
    public int coord_mode = 0;//编辑大地坐标时，坐标的类型
    public int coord_format = 0;

    @Transient
    private LonLat ll_gcj = new LonLat(0, 0);//火星坐标系 (GCJ-02)

    public LonLat getLL_gcj() {
        return Utils.wgs84togcj02(longitude, latitude);
    }

    @Generated(hash = 1536926665)
    public WayPoint() {
    }

    public WayPoint(String name, LonLat ll) {
        if (ll == null) {
            ll = new LonLat();
        }
        if (name == null || name.length() < 1) {
            name = "";
        }
        this.id = null;
        this.name = name;
        this.longitude = ll.GetLon();
        this.latitude = ll.GetLat();
        this.datetime = System.currentTimeMillis();
        //初始化需6ms， 导致导入慢，暂时不用
//        GeoHash g = new GeoHash(ll);
//        g.sethashLength(10);//精确到1米
//        this.geohash = g.getGeoHashBase32();
    }

    public WayPoint(NavFrameSDK.POIDescription data) {
        this.id = null;

        if (data == null) {
            return;
        }

        this.name = data.name;
        this.longitude = data.position.lon;
        this.latitude = data.position.lat;
        this.datetime = System.currentTimeMillis();

        GeoHash g = new GeoHash(latitude, longitude);
        g.sethashLength(10);//精确到1米
        this.geohash = g.getGeoHashBase32();
    }

    public WayPoint(WayPoint wayPoint, long routeid) {
        if (wayPoint == null) {
            return;
        }
        this.icon_num = wayPoint.getIcon_num();
        this.name = wayPoint.getName();
        this.longitude = wayPoint.getLongitude();
        this.latitude = wayPoint.getLatitude();
        this.altitude = wayPoint.getAltitude();
        this.note = wayPoint.getNote();
        this.depth = wayPoint.getDepth();
        this.datetime = System.currentTimeMillis();
        this.picurl = wayPoint.getPicurl();
        this.type = wayPoint.getType();
        this.range = wayPoint.getRange();
        this.localtype = wayPoint.getLocaltype();
        this.routeid = routeid;

        GeoHash g = new GeoHash(latitude, longitude);
        g.sethashLength(10);//精确到1米
        this.geohash = g.getGeoHashBase32();
    }

    @Generated(hash = 654267872)
    public WayPoint(Long id, int icon_num, String name, double longitude, double latitude,
            double altitude, String note, double depth, long datetime, String picurl,
            int type, double range, int localtype, Long routeid, String geohash, String strLL,
            int coord_mode, int coord_format) {
        this.id = id;
        this.icon_num = icon_num;
        this.name = name;
        this.longitude = longitude;
        this.latitude = latitude;
        this.altitude = altitude;
        this.note = note;
        this.depth = depth;
        this.datetime = datetime;
        this.picurl = picurl;
        this.type = type;
        this.range = range;
        this.localtype = localtype;
        this.routeid = routeid;
        this.geohash = geohash;
        this.strLL = strLL;
        this.coord_mode = coord_mode;
        this.coord_format = coord_format;
    }

    public LonLat getLL() {
        return new LonLat(longitude, latitude);
    }

    public void setLL(LonLat ll) {
        if (ll != null) {
            longitude = ll.GetLon();
            latitude = ll.GetLat();

//            GeoHash g = new GeoHash(latitude, longitude);
//            g.sethashLength(10);//精确到1米
//            this.geohash = g.getGeoHashBase32();
        }
    }

    public void setLL(double llon, double llat) {
        longitude = llon;
        latitude = llat;

//        GeoHash g = new GeoHash(latitude, longitude);
//        g.sethashLength(10);//精确到1米
//        this.geohash = g.getGeoHashBase32();
    }

    public int getTypeIcon() {
        if (icon_num < 0 || icon_num >= TYPE_IDS.length) {
            icon_num = 0;
        }
        return TYPE_IDS[icon_num];
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getIcon_num() {
        return this.icon_num;
    }

    public void setIcon_num(int icon_num) {
        this.icon_num = icon_num;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getLongitude() {
        return this.longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getLatitude() {
        return this.latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getAltitude() {
        return this.altitude;
    }

    public void setAltitude(double altitude) {
        this.altitude = altitude;
    }

    public String getNote() {
        return this.note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public double getDepth() {
        return this.depth;
    }

    public void setDepth(double depth) {
        this.depth = depth;
    }

    public long getDatetime() {
        return this.datetime;
    }

    public void setDatetime(long datetime) {
        this.datetime = datetime;
    }

    public String getPicurl() {
        return this.picurl;
    }

    public void setPicurl(String picurl) {
        this.picurl = picurl;
    }

    public int getType() {
        return this.type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getLocaltype() {
        return this.localtype;
    }

    public void setLocaltype(int localtype) {
        this.localtype = localtype;
    }

    public Long getRouteid() {
        return this.routeid;
    }

    public void setRouteid(Long routeid) {
        this.routeid = routeid;
    }

    public double getRange() {
        return this.range;
    }

    public void setRange(double range) {
        this.range = range;
    }


    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public String getGeohash() {
        return this.geohash;
    }

    public void setGeohash(String geohash) {
        this.geohash = geohash;
    }

    public int getCoord_mode() {
        return this.coord_mode;
    }

    public void setCoord_mode(int coord_mode) {
        this.coord_mode = coord_mode;
    }

    public int getCoord_format() {
        return this.coord_format;
    }

    public void setCoord_format(int coord_format) {
        this.coord_format = coord_format;
    }

    public String getStrLL() {
        return this.strLL;
    }

    public void setStrLL(String strLL) {
        this.strLL = strLL;
    }

}
